<template>
  <div class="list-table">
    <el-table v-loading="loading" :data="xirrBaseDetailsList" border tooltip-effect="darkTable" :row-style="tableRowStyle">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('业务类型')" align="center" prop="operateType" show-overflow-tooltip :formatter="operateTypeFormat" min-width="120" />
      <el-table-column :label="$t('现金流类型')" align="center" prop="type" show-overflow-tooltip :formatter="typeFormat" min-width="120" />
      <el-table-column :label="$t('业务发生时间')" align="center" prop="actualTime" show-overflow-tooltip min-width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actualTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('参与计算时间')" align="center" prop="calculationTime" show-overflow-tooltip min-width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.calculationTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('金额(元)')" align="center" prop="money" show-overflow-tooltip min-width="120">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.money) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listXirrBaseDetails } from '@/api/sys/xirrBase/details/xirrBaseDetails'
export default {
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 计算明细表格数据
          xirrBaseDetailsList: [],
          // 现金流类型  预计 实际字典
          typeOptions: [],
          // 类型：投资、回款、费用字典
          operateTypeOptions: [],
          // 弹出层标题
          title: '计算使用现金流',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              xirrId: undefined,
              type: undefined,
              actualTime: undefined,
              calculationTime: undefined,
              money: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
    this.getDicts('cash_flow_operate_type').then(response => {
      this.operateTypeOptions = response.data
    })
    this.getDicts('cash_flow_type').then(response => {
      this.typeOptions = response.data
    })
  },
  methods: {
    init(xIrrId) {
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10
      this.queryParams.xirrId = xIrrId
      this.getList()
    },
    /** 查询XIRR计算明细列表 */
    getList() {
        this.loading = true
        listXirrBaseDetails(this.queryParams).then(response => {
            this.xirrBaseDetailsList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },
    typeFormat(row) {
      return this.selectDictLabel(this.typeOptions, row.type)
    },
    operateTypeFormat(row) {
      return this.selectDictLabel(this.operateTypeOptions, row.operateType)
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            xirrId: undefined,
            type: undefined,
            actualTime: undefined,
            calculationTime: undefined,
            money: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },

    /** 导出按钮操作 */
    exportHandle() {
        this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            this.downLoadExcel('/details/xirrBaseDetails/export', this.queryParams)
        }).catch(() => {
        })
    },
    tableRowStyle({ row }) {
      if (row.type === 'YJ') {
        return {
          backgroundColor: 'rgba(87,230,255,0.47)'
        }
      }
      return {}
    }
  }
}
</script>
